package com.jiangchuang.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.jiangchuang.domain.Result;
import com.jiangchuang.domain.entity.Dish;
import com.jiangchuang.domain.response.GetDishByIdRes;
import com.jiangchuang.service.IDishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api")
@Api(tags = "菜品管理")
@RestController
public class DishController {
    @Autowired
    private IDishService dishService;

    @ApiOperation(value = "获取菜品分页 reviewStatus:null所有，3-审核不通过，5-被举报")
    @GetMapping("/getDishesPage")
    public Result getDishesPage(Integer reviewStatus, @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "20") int pageSize){
        return Result.ok(dishService.getDishesPage(reviewStatus, pageNo, pageSize));
    }

    @ApiOperation(value = "获取未人工审核菜品分页")
    @GetMapping("/getUnCheckedDishes")
    public Result getUnCheckedDishes(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "20") int pageSize){
        return Result.ok(dishService.getUnCheckedDishes(pageNo, pageSize));
    }

    @ApiOperation(value = "获取未人工审核的图片")
    @GetMapping("/getUnCheckedImg")
    public Result getUnCheckedImg(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "20") int pageSize){
        return Result.ok(dishService.getUnCheckedImg(pageNo, pageSize));
    }

    @ApiOperation(value = "审核菜品")
    @PostMapping("/reviewDish")
    private Result reviewDish(Integer tblType, Integer id, Integer reviewStatus){
        dishService.reviewDish(tblType,id,reviewStatus);
        return Result.ok();
    }

    @ApiOperation(value = "根据菜品ID返回详情")
    @PostMapping("/getDishById")
    private Result<GetDishByIdRes> getDishById(Integer did){
        return Result.ok(dishService.getDishById(did));
    }

    @ApiOperation(value = "获取当前用户菜单（所有菜品）分页")
    @GetMapping("/getUserDishPage")
    private Result<PageInfo<Dish>> getUserDishPage(Integer uid, @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "20") int pageSize){
        return Result.ok(dishService.getUserDishPage(uid, pageNo, pageSize));
    }

}
